package com.yunysha.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.yunysha.controller.YunyshaController;

/**
 * Servlet implementation class GridDataPopulation
 */
public class CompanyMasterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CompanyMasterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println(" --> doPost ");
		if(request.getParameter("oper")!=null)
		{
			
			System.out.println(request.getParameter("oper"));
		}
		
		YunyshaController yController = new YunyshaController();
		

		JSONArray jArray = new JSONArray();
		String selectClause="txtCode,txtCompanyName,txtCStatus,txtCZone,txtCState,txtCCity";
		String table="companyMaster";
		jArray = yController.retrieveData(selectClause,table);
		JSONObject jObj = new JSONObject();
		jObj.element("page", 1);
		jObj.element("total", jArray.size());
		jObj.element("rows", jArray);

		PrintWriter out = response.getWriter();
		response.setContentType("application/json");
		out.println(jObj);
		out.close();

		
		
	}

}
